<template>
    <div>
        <Modal :title="modalTitle" v-model="modalVisible" :mask-closable='false' :width="600" :styles="{top: '100px'}">
            <Form ref="form" :model="form" :label-width="80" >
                <FormItem label="可报名人数" prop="signCount">
                    <InputNumber v-model="form.signCount" type="number" :min="1" style="width:300px"/>
                </FormItem>
                <FormItem label="考试日期" prop="examTime">
                    <DatePicker  type="date" format="yyyy-MM-dd"  @on-change="examChange" :value="form.examTime" style="width:300px" placeholder="请输入考试日期"></DatePicker>
                </FormItem>
                <FormItem label="考试时间" prop="examStartTime">
                    <TimePicker type="timerange" format="HH:mm:ss"  @on-change="selectDateRange" :value="[form.examStartTime,form.examendTime]" style="width:300px" placeholder="请输入报名时间"></TimePicker>
                </FormItem>
            </Form>
            <div slot="footer">
                <Button type="text" @click="cancelUser">取消</Button>
                <Button type="primary" :loading="submitLoading" @click="handelSubmit">提交</Button>
            </div>
        </Modal>
    </div>
</template>

<script>
    import {timeEdit} from "@/api/bus";
    export default {
        name: "timeArrangeDrawer",
        components: {

        },
        data() {
            return {
                type:0,
                errorPass: "",
                deptLoading: false,
                modalTitle: "添加条件",
                submitLoading: false,
                modalVisible: false,
                form: {
                    id: '',
                    status: 1,
                    signCount: 1,
                    signlastCount: 0,
                    examStartTime: '',
                    examendTime: '',
                    examTime: '',
                    examseasonId: ''
                }
            }
        },
        methods: {
            init() {

            },
            showDrawer(params) {
                this.modalVisible = true;
                this.form.examseasonId = params.examseasonId;
                if (params.id) {
                    this.modalTitle = "编辑场次时间";
                    this.form.id = params.id;
                    this.form.signCount = params.signCount;
                    this.form.examStartTime = params.examStartTime;
                    this.form.examendTime = params.examendTime;
                    this.form.examTime = params.examTime;
                    this.form.signlastCount = params.signlastCount;
                }else{
                    this.modalTitle = "添加场次时间";
                    this.form.id = '';
                    this.form.signCount = 1;
                    this.form.examStartTime = '';
                    this.form.examendTime = '';
                    this.form.examTime = '';
                    this.form.signlastCount = 0;
                }
            },
            selectDateRange(v) {
                if (v) {
                    this.form.examStartTime = v[0];
                    this.form.examendTime = v[1];
                }
            },
            examChange(data1,data2){
                this.form.examTime = data1;
            },
            cancelUser() {
                this.modalVisible = false;
            },
            handelSubmit() {
                this.$refs.form.validate(valid => {
                    if (valid) {
                        this.submitLoading = true;
                        // 添加 避免编辑后传入id等数据 记得删除
                        timeEdit(this.form).then(res => {
                            this.submitLoading = false;
                            if (res.status === true) {
                                this.$Message.success("添加成功");
                                this.$parent.getDataList();
                                this.modalVisible = false;
                            }
                        });
                    }
                });
            }
        },
        mounted() {

        }
    }
</script>

<style>

</style>